/*
 * Naive.cpp
 *
 *  Created on: 14-06-2013
 *      Author: Krzychu
 */

#include "Naive.h"

#include "Config.h"

Naive::Naive()
{

}

Naive::~Naive()
{

}

std::string Naive::getName()
{
	return "Naive Search";
}

searchResult Naive::execute(std::string text, std::string pattern)
{
	searchResult result;
	result.iterationsTaken = 0;

	for (unsigned int i = 0; i < text.size() - pattern.size() - 1; i++)
	{
		result.iterationsTaken++;

		if (text.substr(i, pattern.size()).compare(pattern) == 0)
		{
			result.positionsFound.push_back(i);
			if (Config::getInstance()->getFindOneOccurence())
			{
				return result;
			}
		}
	}

	return result;
}

